package com.emip.servlet.baseinfo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.emip.bean.ExpFlagBean;
import com.emip.config.SysParams;
import com.emip.pojo.Table;
import com.emip.service.ExpFlagService;
import com.emip.util.TableFormat;

@Controller
@RequestMapping(value="/base/expFlag")
public class ExpFlagAction {

	@Autowired
	ExpFlagService expFlagService;
	
	@RequestMapping(value="/management")
	public String index() {		
		return "/baseInfo/ExpFlagManagement";
	}
	
	@RequestMapping(value="/getAllExpFlags")
	public @ResponseBody Table<ExpFlagBean> getAllExpFlags() {
		List<ExpFlagBean> result = expFlagService.getAll();
		int records = result.size();
		int totalPages = records / SysParams.gridDefinedRowNumber + 1;
		return new TableFormat<ExpFlagBean>().formTable(totalPages, 1, records, result);

	}
	
	@RequestMapping(value="/getExpFlagByID",method=RequestMethod.POST, headers="Accept=application/json")
	public @ResponseBody ExpFlagBean getExpFlagByID(@RequestParam("id") int id) {
		return expFlagService.getExpFlagByID(id);
	}
	
	@RequestMapping(value="/addExpFlag",method=RequestMethod.POST)
	public @ResponseBody ExpFlagBean addExpFlag(@RequestParam("flag")  String flag, @RequestParam("desp") String desp,
			@RequestParam("inStat") String inStat, @RequestParam("showNum") String showNum) {
		return expFlagService.addExpFlag(flag, desp, inStat, showNum);
	}
	
	@RequestMapping(value="/updateExpFlag",method=RequestMethod.POST)
	public @ResponseBody ExpFlagBean updateExpFlag(@RequestParam("id") int id, @RequestParam("flag")  String flag, 
			@RequestParam("desp") String desp, @RequestParam("inStat") String inStat, @RequestParam("showNum") String showNum) {
		return expFlagService.updateExpFlag(id, flag, desp, inStat, showNum);		
	}
	
	@RequestMapping(value="/deleteExpFlag",method=RequestMethod.POST)
	public @ResponseBody String deleteExpFlag(@RequestParam("id") int id) {
		expFlagService.deleteExpFlag(id);
		return "success";
	}
}
